package com.zhongge.alloj.linkedlist;
/**
 * @ClassName Test03
 * @Description TODO 回文链表
 * @Author zhongge
 * @Date 2025/9/25 9:00
 * @Version 1.0
 */
public class Test03 {
    public boolean chkPalindrome(ListNode A) {
        if (A == null || A.next == null) {
            return true;
        }
        // write code here
        ListNode slow = A;
        ListNode fast = A;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        ListNode last = null;
        ListNode cur = slow;
        while (cur != null) {
            ListNode curN = cur.next;
            cur.next = last;
            last = cur;
            cur = curN;
        }
        while (A.next != slow) {
            if (A.val != last.val){
                return false;
            } else {
                A = A.next;
                last = last.next;
            }
        }
        return true;
    }
}
